package com.shj.web.controller;

import com.shj.model.PageRequest;
import com.shj.model.PageResult;
import com.shj.model.SysConclusion;
import com.shj.model.SysSubject;
import com.shj.service.SysConclusionService;
import com.shj.service.SysSubjectService;
import com.shj.util.FileUtil;
import com.shj.util.MyTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * (SysConclusion)表控制层
 *
 * @author makejava
 * @since 2020-03-12 12:49:35
 */
@Controller
@RequestMapping("/conclusion")
public class SysConclusionController {
    /**
     * 服务对象
     */
    @Resource
    private SysConclusionService sysConclusionService;

    /**
     * @Description 管理员查询所有申请结题的项目
     * @author songhuajian
     * @date 2020/6/8 16:44
     */
    @ResponseBody
    @GetMapping("/admin/list")
    public PageResult findForConclusion(PageRequest pageRequest, String leaderId) {
        return sysConclusionService.findPage(pageRequest, leaderId);
    }

    /**
     * @Description 教师查询结题的项目
     * @author songhuajian
     * @date 2020/6/8 16:45
     */
    @ResponseBody
    @GetMapping("/leader/list")
    public PageResult findForLeaderConclusion(PageRequest pageRequest, String leaderId) {
        return sysConclusionService.findPage(pageRequest, leaderId);
    }

    /**
     * 查询项目详情
     * @param id
     * @return
     */
    @RequestMapping("/one")
    @ResponseBody
    public SysConclusion getOne(int id) {
        return sysConclusionService.queryById(id);
    }

    /**
     * @Description 结题申请
     * @author songhuajian
     * @date 2020/6/8 16:45
     */
    @PostMapping("/leader/add")
    @ResponseBody
    public void conclusion(MultipartFile file, SysConclusion sysConclusion) throws IOException {
        // 保存结题申请书
        String url = FileUtil.mvcFileUpload(file);
        String time = MyTimeUtil.getForTimestamp().toString();
        sysConclusion.setConFile(url);
        sysConclusion.setConTime(time);
        sysConclusion.setConStatus(0);

        sysConclusionService.insert(sysConclusion);
    }

    /**
     * 审核结题项目
     * @param sysConclusion
     * @return
     */
    @RequestMapping("/admin/review")
    @ResponseBody
    public SysConclusion review(SysConclusion sysConclusion) {
        return sysConclusionService.review(sysConclusion);
    }


}